const xq = 'https://m.douban.com/rexxar/api/v2/'
const bq = 'https://m.douban.com/rexxar/api/v2/'
const dp = 'https://m.douban.com/rexxar/api/v2/'
const count=5
Page({
    data:{
        start:0,
        type:'',
        id:''
    },
    onLoad(option){
        console.log(option)
        let {type,id} = option
        this.setData({
            type,id
        })
        wx.request({
          url: xq+option.type+'/'+option.id,
          success:res=>{
              console.log(res.data)
              let mygenres = res.data.genres.join('/')
              let myactors = res.data.actors.slice(0,3).map(v=>{
                  return v.name
              }).join('/')
              let rate = res.data.rating.value
              //console.log(rate)
              //星星个数
              let lights = 'a'.repeat(Math.floor(rate / 2))
              //半个星星个数
              let halfs = rate % 2 != 0
              //灰色星星个数
              let grays = 'a'.repeat(Math.floor((10 - rate) / 2))
              let rateText = rate && rate > 0 ? rate.toFixed(1) : "未评分"
              this.setData({
                  xq:res.data,
                  myactors,
                  mygenres,
                  rateText: rateText,
                  lights: lights,
                  halfs: halfs,
                  grays: grays
              })
          }
        })
        wx.request({
          url: bq+option.type+'/'+option.id+'/tags?count=8',
          success:res=>{
              this.setData({ bq:res.data})
           
          }
        })
        wx.request({
          url: dp+option.type+'/'+option.id+'/interests',
          success:res=>{
              this.setData({dp:res.data})
            
          }
        })
    },
    stars: function () {
        let that = this //定义全局变量
        let rate = that.properties.rate
        //console.log(rate)
        //星星个数
        let lights = 'a'.repeat(Math.floor(rate / 2))
        //半个星星个数
        let halfs = rate % 2 != 0
        //灰色星星个数
        let grays = 'a'.repeat(Math.floor((10 - rate) / 2))
        let rateText = rate && rate > 0 ? rate.toFixed(1) : "未评分"
        that.setData({
            rateText: rateText,
            lights: lights,
            halfs: halfs,
            grays: grays
        })
    },
    onReachBottom(){
        this.setData({
            start:this.data.start + count
        })
       let url=dp +this.data.type+'/'+this.data.id+'/interests?start='+this.data.start+'&count='+count
       console.log(url)
       wx.request({
         url,
         success:res=>{
             console.log(res)
             let dp = this.data.dp
             let ttt = dp.interests
             console.log(ttt)
             let sss = res.data.interests
             console.log(sss)
             ttt = ttt.concat(sss)
             dp.interests = ttt
             this.setData({
                 dp
             })
         }
       })
    }
})